<?php
class Message_model extends CI_Model {

    var $table   = 'message';

    function __construct()
    {
        parent::__construct();
    }
    
    function get_list($where = '', $cond = array(), $offset = 0, $limit = 20){
    	if (!empty($where)){
    		$where = 'where ' . $where;
    	}
        $sql = 'select id, from_user, msg_id, type, msg_time, title, summary, content, media_id, thumb_media_id, picurl, format, location_x, location_y, scale, label, url, add_time from '
        	. "{$this->table} {$where} order by id desc limit {$offset}, {$limit}";
		$re_obj = $this->db->query($sql, $cond);
		
		if ($re_obj->num_rows() > 0){
			$re = $re_obj->result_array();
			$re_obj->free_result();
		}else {
			$re = array();
		}
		return $re;
    }
    
    function add($items = array()){
    	$sql = "insert into {$this->table} (from_user, msg_id, type, msg_time, title, summary, content, media_id, thumb_media_id, picurl, format, location_x, location_y, scale, label, url, add_time)"
    		. " values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    	return $this->db->query($sql, $items);
    }

}
